package com.ruoyi.project.system.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SiyuCharge;
import com.ruoyi.project.system.domain.SiyuQuery;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SiyuChargeMapper;
import com.ruoyi.project.system.mapper.SiyuQueryMapper;
import com.ruoyi.project.system.mapper.SiyuShareCodeMapper;
import com.ruoyi.project.system.service.ISiyuChargeService;
import com.ruoyi.project.system.service.ISiyuQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ruoyi.framework.manager.factory.AsyncFactory.fee;

/**
 * 收费记录Controller
 *
 * @author ruoyi
 * @date 2024-10-28
 */
@RestController
@RequestMapping("/system/charge")
public class SiyuChargeController extends BaseController {

    @Autowired
    private ISiyuChargeService siyuChargeService;

    @Autowired
    private  ISiyuQueryService iSiyuQueryService;

    @Autowired
    private SiyuChargeMapper siyuChargeMapper;

    @Autowired
    private SiyuQueryMapper siyuQueryMapper;

    @GetMapping("/yysCharge")
    public int yysCharge(Integer queryId) {
        return siyuChargeMapper.yysCharge(queryId);
    }

    @GetMapping("/addYysCharge")
    public void addYysCharge(Integer queryId) {
        SiyuQuery siyuQuery = siyuQueryMapper.selectSiyuQueryByQueryId(queryId);
        // 异步扣费判断
        siyuQuery.setId(2);
        iSiyuQueryService.baseFee(siyuQuery, "运营商");
    }

    @Anonymous
    @GetMapping("/referAuth")
    public AjaxResult referAuth(Integer ID, String ac) {
        SiyuQuery siyuQuery = siyuQueryMapper.selectSiyuQueryByQueryId(ID);
        return success(siyuChargeMapper.selectResult(siyuQuery.getUserId(), ac));
    }

    /**
     * 查询收费记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:charge:list')")
    @GetMapping("/list")
    public TableDataInfo list(SiyuCharge siyuCharge) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        if (!user.isAdmin()) {
            siyuCharge.setUserId(user.getUserId().intValue());
        }
        startPage();
        List<SiyuCharge> list = siyuChargeService.selectSiyuChargeList(siyuCharge);
        return getDataTable(list);
    }

    /**
     * 删除进件记录
     */
    @PreAuthorize("@ss.hasPermi('system:charge:remove')")
    @DeleteMapping("/{queryIds}")
    public AjaxResult remove(@PathVariable Integer[] queryIds) {
        return toAjax(siyuChargeMapper.deleteSiyuChargeByIds(queryIds));
    }

}
